﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once

#include "NdbObjectSchematic.h"
#include "IExternalData.h"
#include "IStructureBeam.h"
#include "NdbDataSchema.h"
#include "RegenDataSchema.h"

namespace gcmp
{
    class IInstance;
    struct StructureBeamInput;

    class StructureBeam : public NdbObjectSchematic, public IStructureBeam
    {
        DATA_BEGIN(gcmp, StructureBeam, gcmp::NdbObjectSchematic, 87EC568B - F425 - 4849 - A738 - 6A65FFE861C4, gmstructure)
            DATA_TRANSIENT(IElement*, pOwnerElement)
            DATA(ConcreteStrengthGradeType, ConcreteStrengthGrade)
            DATA_REGEN(double, Volume)
            DATA_REGEN(double, Length)
            DATA_REGEN(double, TopElevation)
            DATA_REGEN(double, StartBottomElevation)
            DATA_REGEN(double, EndBottomElevation)            
        DATA_END

    public:
        static OwnerPtr<StructureBeam> Create(IInstance* pInstance, const StructureBeamInput* pInput);

        // 继承自IStructureBeam
        DECLARE_STRUCTURE_INSTANCE_METHODS;

        virtual double GetVolume() const override { return GetVolume__(); }
        bool SetVolume(double volume) { SetVolume__(volume); return true; }
        virtual double GetLength() const override { return GetLength__(); }
        bool SetLength(double length) { SetLength__(length); return true; }

    public:
        //高程信息
        bool SetTopElevation(double value) { SetTopElevation__(value); return true; }
        double GetTopElevation() const { return GetTopElevation__(); }

        bool SetStartBottomElevation(double value) { SetStartBottomElevation__(value); return true; }
        double GetStartBottomElevation() const { return GetStartBottomElevation__(); }

        bool SetEndBottomElevation(double value) { SetEndBottomElevation__(value); return true; }
        double GetEndBottomElevation() const { return GetEndBottomElevation__(); }

    public:
        bool SetOwnerElement(IElement* pOwnerElement) { m_pOwnerElement = pOwnerElement; return true; }
        IElement* GetOwnerElement() { return m_pOwnerElement; }
        const IElement* GetOwnerElement() const { return m_pOwnerElement; }
        IDocument* GetDocument() const;
        ElementId GetOwnerElementId() const;
        virtual NdbObject* GetTopOwnerObject() const override;

    public:
        void UpdateForWeakParentDeletion(const std::set<ElementId>& deletedElementIds);
        void ReportParents(IElementParentReporter& reporter) const;
        void GetCalculators(ICalculatorCollection* calculators) const;

        void ReportParameterDefinitions(std::vector<int>* pParamDefIds) const;
        OwnerPtr<IParameter> GetNativeParameter(int paramDefId) const;
        bool SetNativeParameter(const IParameter *param, std::wstring* errorMsg = nullptr);
        bool IsParameterModifiable(int paramDefId) const;

        void Report(const gcmp::ICopyContext & copyContext, gcmp::ICopyStrategyReporter& reporter) const;
    };
}
